

from rest_framework import serializers
from orders.models import OrderInfo,OrderGoods
from goods.models import SKU


class OrderSimpleSerializer(serializers.ModelSerializer):
    # create_time = serializers.DateTimeField(
    #     format="%Y/%m/%d %H:%M:%S"
    # )

    class Meta:
        model = OrderInfo
        fields = [
            'order_id',
            'create_time',
        ]

        extra_kwargs = {
            'create_time': {'format': "%Y/%m/%d %H:%M:%S"}
        }




class SKUSimpleSerializer(serializers.ModelSerializer):
    class Meta:
        model = SKU
        fields = [
            'name',
            'default_image_url'
        ]


class OrderGoodsModelSerializer(serializers.ModelSerializer):
    # 1、SKU模型类对象；2、单一
    sku = SKUSimpleSerializer()

    class Meta:
        model = OrderGoods
        fields = [
            'count',
            'price',
            'sku'
        ]


class OrderDetailSerializer(serializers.ModelSerializer):
    user = serializers.StringRelatedField()

    # 1、是从表OrderGoods数据；2、多个
    skus = OrderGoodsModelSerializer(many=True)

    class Meta:
        model = OrderInfo
        fields = "__all__"




















